<?php 

class Ext_Register_Validate_Email extends Ext_Validate_Abstract
{
    protected $_email;
    
    protected $_messager;
    const EXISTS              = 'emailExists';
    protected $_messageTemplates = array(
        self::EXISTS              => "This email already exists.",
    );
    
    public function __construct($email)
    {
        $this->_email = $email;
        $this->_messager = new Ext_Messager($this->_messageTemplates);
    }
    
    public function isValid()
    {
        $validatorChain = new Zend_Validate();
        $validatorChain
            ->addValidator(new Zend_Validate_NotEmpty(), true)
            ->addValidator(new Zend_Validate_EmailAddress(), true)
            ;
        if(!$validatorChain->isValid($this->_email)) {
            $this->addTitleMessages('Email', $validatorChain->getMessages());
            return false;
        }
        
        
        return true;
    }
}
